
<%
	task.doTask();
%>
<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript">

function rowClicked(row,contract_id)
{
	if (contract_id != null) setValue("contract_id",contract_id);
	highlightOn(row);
}


function doReport()
{
	hide("physical_buttons");
	hide("physical_list_view");
	show("physical_report");
}

function cancelReport()
{
	show("physical_buttons");
	show("physical_list_view");
	hide("physical_report");
}

</script>
<form method="POST" name="formMain" action="" onSubmit="">				  
	<table width="100%"  border="0" class="style2">
		<tr>
			<td colspan="4"><img src="images/weighing.jpg" width="200" height="20"></td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
          <tr bgcolor="#EEEEEE" class="style3" align="center" style="font-weight:bold">
            <td width="10%"><label id="e11">Type </label></td>
            <td width="12%">Origin</td>
            <td width="13%"><label id="e13">Quality</label></td>
            <td width="27%">Grade</td>
            <td width="14%"><label id="e14">Buyer/Seller</label></td>
            <td width="12%"><label id="e15">Status</label></td>
            <td width="12%"><label id="e16">Last Date</label></td>
          </tr>
          <tr>
            <td valign="top"><select name="type" size="7" id="type" onChange="doPost();" class="style11" style="width:100%;">
              <option value="0" selected>All</option>
              <option value="I">Import</option>
              <option value="IP">In-Process</option>
              <option value="XP">Ex-Process</option>
              <option value="E">Export</option>
              <%task.getResponse().setSelected("type");%>
            </select></td>
            <td valign="top"><select name="origin_id" id="origin_id" size=7 class="style11" style="width:100%;" onChange="setValue('quality_id',0);setValue('grade_id',0);doPost();">
              <option value="0" selected>All</option>
              <%task.getResponse().setOption(task.getMasterList("origin_master"));%>
              <%task.getResponse().setSelected("origin_id");%>
            </select></td>
            <td valign="top"><select name="quality_id" id="quality_id" size=7 class="style11" style="width:100%;" onChange="setValue('grade_id',0);doPost();">
              <option value="0" selected>All</option>
              <%task.getResponse().setOption(task.getMasterList("quality_master"));%>
              <%task.getResponse().setSelected("quality_id");%>
            </select></td>
            <td valign="top"><select name="grade_id" id="grade_id" size=7 class="style11" style="width:100%;" onChange="doPost();">
              <option value="0" selected>All</option>
              <%task.getResponse().setOption(task.getMasterList("grade_master"));%>
              <%task.getResponse().setSelected("grade_id");%>
            </select></td>
             <td valign="top"><select name="supplier_buyer_id" id="supplier_buyer_id" size=7 class="style11" style="width:100%;" onChange="doPost();">
               <option value="0" selected>All</option>
               <%task.getResponse().setOption(task.getCompanyList("supplier"));%>
               <%task.getResponse().setSelected("supplier_buyer_id");%>
             </select></td>
             <td valign="top"><select name="status" size="7" id="status" onChange="doTask()" class="style11" style="width:100%;">
               <option value ="0" selected>All</option>
               <option value ="F">Fixed</option>
               <option value ="U">Unfixed</option>
               <option value ="D">Delivered</option>
               <option value ="P">Undelivered</option>
               <%task.getResponse().setSelected("status");%>
             </select></td>
             <td valign="top">&nbsp;
</td>
          </tr>
		  <tr id="physical_list_view">
			  <td colspan="7"  valign="top">
<div style="overflow:scroll; height:250px;">		  
			  <table width="100%"  border="0" cellpadding="0" cellspacing="1" class="style2">
<script language="javascript">
	var table = 'warehouse.weighing.import.list-view';
</script>			  
                <tr align="center" bgcolor="#EEEEEE" style="font-weight:bold; cursor:pointer" title='Click on columns to sort' onMouseOver="window.status='Click on columns to sort'">
                  <td width="23"  rowspan="2" onClick="doPost()"><img src="images/refresh.gif" width="18" height="18" class="style3"></td>
                  <td width="70"  rowspan="2" onClick="doSort(table,'ct.ref_number')"><label id="e21">Contract Ref </label></td>
                  <td width="45"  rowspan="2" onClick="doSort(table,'ct.contract_no')">Broker<br>No</td>
                  <td width="100" rowspan="2" onClick="doSort(table,'buyer_seller')"><label id="e22">Buyer/Seller</label></td>
                  <td width="65"  rowspan="2" onClick="doSort(table,'origin')">Origin</td>
                  <td width="65"  rowspan="2" onClick="doSort(table,'quality')"><label id="e23">Quality</label></td>
                  <td rowspan="2"             onClick="doSort(table,'grade')"><label id="e24">Grade</label></td>
                  <td colspan="2">Shipping Period</td>
                  <td colspan="3">Tons</td>
                  <td colspan="2">Allocation</td>
                </tr>
                <tr align="center" bgcolor="#EEEEEE" style="font-weight:bold; cursor:pointer">
                  <td width="60" onClick="doSort(table,'ct.first_date')">From</td>
                  <td width="60" onClick="doSort(table,'ct.last_date')">To </td>
                  <td width="50">Total</td>
                  <td width="50">Del.</td>
                  <td width="50">Pend.</td>
                  <td width="50">Yes.</td>
                  <td width="50">No.</td>
                </tr>
<%
	ResultSet rs = task.getContract_Detail();
	Record rc = new Record();
	while (rs.next()) {
		rc.setRs(rs);
		float tons = rc.getFloatValue("tons");
		float delivered_tons = rc.getFloatValue("receive_tons");
		float balanced_tons = tons - delivered_tons;
		
		float unfixed_tons = rc.getFloatValue("unfixed_tons");
		
		String color = "";//rc.getIntValue("status") !=2 ? "#5392DD" : "#000000";
		if ((balanced_tons > 0) && (unfixed_tons > 0)) color = "#FF0000";
		if ((balanced_tons == 0) && (unfixed_tons > 0)) color = "#FFFF66";
		if ((balanced_tons > 0) && (unfixed_tons == 0)) color = "#33CCFF";

		float tons_allocated = rc.getFloatValue("tons_allocated");
		float tons_unallocated = tons - tons_allocated;
		
%>				
                <tr style="font-size:11px" onClick="rowClicked(this,<%=rs.getInt("id")%>)" onDblClick="setValue('view',1);doTask();">
                  <td align="right"><%=rs.getRow()%></td>
                  <td style="color:<%=color%>"><%=rs.getString("ref_number")%></td>
                  <td><%=rc.getString("contract_no")%></td>
                  <td><%=rc.getString("buyer_seller")%></td>
                  <td><%=rc.getString("origin")%></td>
                  <td><%=rc.getString("quality")%></td>
                  <td><%=rc.getString("grade")%></td>
                  <td align="center"><%=Utils.dateToStr(rs.getDate("last_date"))%></td>
                  <td align="center"><%=Utils.dateToStr(rs.getDate("last_date"))%></td>
                  <td align="right"><%=Utils.numberToStr(tons,1)%></td>
                  <td align="right"><%=Utils.numberToStr(delivered_tons,1)%></td>
                  <td align="right"><%=Utils.numberToStr(balanced_tons,1)%></td>
                  <td align="right"><%=Utils.numberToStr(tons_allocated,1)%></td>
                  <td align="right"><%=Utils.numberToStr(tons_unallocated,1)%></td>
                </tr>
<%
	}
	rs.close();
%>				
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td colspan="2">&nbsp;</td>
                  <td colspan="5">&nbsp;</td>
                </tr>
          </table>
</div>		  
			  </td>
		  </tr>

		  <tr id="physical_report" style="display:none">
			  <td colspan="7"  valign="top">
  			<table border="1" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
  			  <tr valign="top"><td height="250px">
			  <table width="100%"  border="0" class="style2">
                <tr class="style1">
                  <td height="42">&nbsp;</td>
                  <td height="42" colspan="3">Submit more information for creating report </td>
                  <td width="3%">&nbsp;</td>
                  <td width="3%">&nbsp;</td>
                  <td width="9%">&nbsp;</td>
                </tr>
                <tr>
                  <td width="6%">&nbsp;</td>
                  <td width="9%">From date </td>
                  <td width="8%"><input type="text" name="report_date_from" id="report_date_from" style="width:80px"></td>
                  <td width="62%"><img src="js/calendar.gif" width="20" height="20" onclick="popUpCalendar(this,'report_date_from','dd-mmm-yy');"></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>To Date </td>
                  <td><input type="text" name="report_date_to" id="report_date_to" style="width:80px"></td>
                  <td><img src="js/calendar.gif" width="20" height="20" onclick="popUpCalendar(this,'report_date_to','dd-mmm-yy');"></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><img src="images/update.gif" width="15" height="15" onClick="doTask(4);">&nbsp;<img src="images/delete.gif" width="15" height="15" onClick="cancelReport();"></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
              </table></td></tr>
			  </table></td>
		  </tr>
		  <tr id="physical_buttons" style="display:">
             <td colspan="7"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
               <tr>
                 <td width="6%">&nbsp;</td>
                 <td width="89%">&nbsp;</td>
                 <td width="5%"><img src="images/report.jpg" width="55" height="18" onClick="doReport();"></td>
               </tr>
             </table></td>
	      </tr>
  </table>
	<input type="hidden" name="uid"  id="uid"  value="<%=user.getuid()%>">
	<input type="hidden" name="task_id"  id="task_id"  value="0">
	<input type="hidden" name="sorted_field"  id="sorted_field"  value="">
	<input type="hidden" name="sorted_table"  id="sorted_table"  value="">	
	<input type="hidden" name="view" id="view" value="<%=task.getRequest().getIntValue("view")%>">	
	<input type="hidden" name="contract_id"  id="contract_id"  value="0">
</form>

